import React, { Component } from 'react'
import {
    BrowserRouter as Router,
    Route,
    Switch,
    Redirect,
  } from "react-router-dom";
  //BrowserRouter和HashRouter感觉差不多
  import User from "../pages/User";
  import Home from "../pages/Home";
  import About from "../pages/About";
  import Text from "../pages/Text";
  import NotFount from "../pages/NotFount";
  import Text2 from "../pages/Text2";
export default class index extends Component<any,any>{
    constructor(props:any){
        super(props);
       this.state={
           list:[{id:1,path:"/",compontent:Home,exact:true},
           {id:2,path:"/about",compontent:About},
           {id:3,path:"/user",compontent:User},
           {id:4,path:"/text/:id",compontent:Text},
           {id:5,path:"/text2",compontent:Text2},
           {id:6,path:"/404",compontent:NotFount},
        ]
       }
    }
  render() {
    return (
      <div><Router>
      <Switch>
        {this.state.list.map((item: { id:number,path: any,compontent:any,exact:any })=>{
            return <Route path={item.path} component={item.compontent} exact={item.exact} key={item.id}></Route>
        })}
        <Redirect path="*" to={"/404"}></Redirect>
      </Switch>
    </Router></div>
    )
  }
}
